package components
{
	import UIFree.uif_component;
	
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.text.TextFormatAlign;
	
	public class c_basePortBar extends c_pcomponent {
		private var _align	: int;
		protected var _barSize	: Object;
		
		public static const TOP		: int = 0;
		public static const RIGHT	: int = 1;
		public static const BOTTOM	: int = 2;
		public static const LEFT	: int = 3;
		public static const CENTER	: int = 4;
		
		public function c_basePortBar(parent:uif_component, a_barSize: Object=30, a_align: int=TOP, styleClass:Object='bar') {
			_align 		= a_align;
			_barSize	= a_barSize;
			super(parent, styleClass);
		}
		
		public function get barSize(): Object {
			return _barSize;
		}
		
		public function get align(): int {
			return _align;
		}
		
		public function set align(a_align: int): void {
			a_align = _align;
			updateBoundsFromParent();
		}
		
		protected function get barSizeAsNumber(): Number {
			return _barSize as Number;
		}
		
		override protected function getPortRect(a_parent: uif_component=null): Rectangle {
			var rect: Rectangle = (a_parent?a_parent:parentComponent).getInner();
			switch (_align) {
				case TOP	: rect.height = barSizeAsNumber;
					break;
				case RIGHT	: rect.left = rect.x + rect.width - barSizeAsNumber;
					break;
				case BOTTOM	: rect.top = rect.y + rect.height - barSizeAsNumber;
					break;
				case LEFT	: rect.width = barSizeAsNumber;
					break;
				case CENTER	: 
					rect.x = (rect.width  - barSize.x) / 2;
					rect.y = (rect.height - barSize.y) / 2;
					rect.width 	= barSize.x;
					rect.height = barSize.y;
					break;
			}
			return rect;
		}
	}
}